package com.technology.education.ui.student.deposit

import androidx.lifecycle.MutableLiveData
import com.technology.education.data.model.ChargePackModel
import com.technology.education.data.model.ExchangeGoodsModel
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

class DepositViewModel : BaseViewModel() {
    var money = ""
    var packageId = ""
    val result = MutableLiveData<ResultState<List<ChargePackModel>>>()
    val chargeResult = MutableLiveData<ResultState<ExchangeGoodsModel>>()
    var selectPos=-1

    /**
     *  "name": "",
    "pageNo": 0,
    "pageSize": 0
     */
    override fun getData() {
        super.getData()
        request({
            apiService.chargePackList(hashMapOf("pageNo" to 1, "pageSize" to 30))
        }, result, isShowDialog = false)
    }

    fun commitOrder() {
        if (money.isEmpty()) {
            toast("请选择或填写充值金额")
            return
        }
        request({
            apiService.placeChargeOrder(
                hashMapOf(
                    "hour" to money,
                    "chargePackId" to packageId
                )
            )
        }, chargeResult, isShowDialog = true)
    }
}